#!/usr/local/bin/ruby

def sieve(n)
	a = Array.new(n+1);
	max = Math.sqrt(n).to_i;
	p = 2;
	while p<=max  do
		i = 2*p
		while i<=n do
			a[i] = 1
			i+=p
		end
		while a[p+=1] == 1 do end
	end
	while a[n] do n-=1 end
	n 
end

x = ARGV[0].to_i
if x == 0
	puts "must input a number"
elsif x < 0
	puts "must input + number"
else
	start = Time.now.to_f
	max_p = sieve(x)
	_end = Time.now.to_f - start
	puts "max p is #{max_p} (take #{_end*1000} ms)"
end